#include "s3c2440_soc.h"
#include "uart.h"

void delay(volatile int sec)
{
	int i,j;
	for(i=0; i<sec; i++)
		for(j=0; j<sec; j++);
}

//#define GPBCON (*(volatile unsigned int*)0x56000010)
//#define GPBDAT (*(volatile unsigned int*)0x56000014)
int led_test()
{
	//int i = 5;
	int val = 0;  /* val: 0b000, 0b111 */
	int tmp;
	/*	GPBCON 0x56000010	GPBCON 0x56000014	*/
	//volatile unsigned int* GPBCON = (volatile unsigned int*)0x56000010;
	//volatile unsigned int* GPBDAT = (volatile unsigned int*)0x56000014;

	/* 先把GPBCON的控制位清0，然后在写入值，防止出现原来是11，写入01还是11*/
	GPBCON &= ~((3<<5*2) | (3<<6*2) | (3<<7*2) | (3<<8*2));
	GPBCON |=  ((1<<5*2) | (1<<6*2) | (1<<7*2) | (1<<8*2));	//GPBCON = 0x15400;

	GPBDAT |=  ((0<<5) | (0<<6) | (0<<7) | (0<<8));	//GPBDAT = 0x0;
	/*
		//tmp = ~val;
		//tmp &= 7;
		//GPFDAT &= ~(7<<5);	//GPBDAT 写错
		tmp |= ~(val&15)
		GPFDAT |= ~(tmp<<5);	//GPBDAT 写错
		delay(500);
		GPFDAT &= ~(tmp<<5);	//GPBDAT 写错
		delay(500);

		val++;
		if (val == 16)
			val = 0;
	*/

	while(0)
	{
		tmp = ~(val&15);
		GPBDAT &= ~(15<<5); //全部清0
		GPBDAT |=  (tmp<<5);
		delay(500);
		val++;
		if(val == 16)
			val = 0;


		/*GPBDAT &= (0<<i);
		delay(500);
		i++;
		if(i == 9)
		{
			i = 5;
			GPBDAT |= ((1<<5) | (1<<6) | (1<<7) | (1<<8));	//GPBDAT = 0x0;
			delay(500);
		}*/
	}

	return 0;
}

